home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / CPPWKBK / CPPV4-3.CPP < prev    next >
C/C++ Source or Header  |  1992-08-25  |  1KB  |  67 lines

  1. #define HEADER "C++ Problem 4.3 by Rick Conn using Borland C++"
  2.  
  3. #include <stdio.h>
  4. #include <time.h>
  5.  
  6. class time_stamp {
  7.   time_t stamp;
  8. public:
  9.   time_stamp();
  10.   void showtime(void);
  11. };
  12.  
  13. time_stamp::time_stamp() {
  14.   time (&stamp);
  15. }
  16.  
  17. void time_stamp::showtime(void) {
  18.   printf("Time Stamp: %s", ctime (&stamp));
  19. }
  20.  
  21. class message : private time_stamp {
  22.   char *msg;
  23. public:
  24.   message (char *);
  25.   void print(void);
  26. };
  27.  
  28. message::message (char *m) {
  29.   msg = m;
  30. }
  31.  
  32. void message::print(void) {
  33.   printf("Message \"%s\"  ", msg);
  34.   showtime();
  35. }
  36.  
  37. class message2 : public time_stamp {
  38.   char *msg;
  39. public:
  40.   message2 (char *);
  41.   void print(void);
  42. };
  43.  
  44. message2::message2 (char *m) {
  45.   msg = m;
  46. }
  47.  
  48. void message2::print(void) {
  49.   printf("Message2 \"%s\"  ", msg);
  50.   showtime();
  51. }
  52.  
  53. void main(void)
  54. {
  55.   printf("%s\n", HEADER);
  56.  
  57.   message  m1("This is a test");
  58.   message2 m2("Another test");
  59.  
  60.   // All member functions of message
  61.   m1.print();
  62.  
  63.   // All member functions of message2
  64.   m2.print();
  65.   m2.showtime();
  66. }
  67.